function traceraypolygon, chm, n, seeds, hthresh
	numseeds = n_elements(seeds[0,*])

	numrays = 4
	extent = ulonarr(numseeds, numrays)

	arrin = ulonarr(2,numrays,n,numseeds)

	cycle = [[0,1], [0,-1], [-1,0], [1,0]]

	;general
	for k=0l, numrays - 1 do begin
		arrin[0,k,*,*] = rebin(seeds[0,*],n,numseeds) + (cycle[0,k] * rebin(lindgen(n),n,n_elements(seeds[0,*])))
		arrin[1,k,*,*] = rebin(seeds[1,*],n,numseeds) + (cycle[1,k] * rebin(lindgen(n),n,n_elements(seeds[0,*])))

	endfor

	for h=0L, numrays - 1 do begin
		for i=0L, numseeds - 1 do begin
			chmA = chm
			chmA[where(chm lt chm[seeds[0,i], seeds[1,i]] - hthresh)]=max(chm)
			val = min(chmA[arrin[0,h,*,i],arrin[1,h,*,i]], minsc)
			extent[i,h] = minsc
		endfor
	endfor
	return, extent

end